this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,r,i,n){"use strict";function a(){return{key:"filterStub",name:i.Loc.getMessage("LANDING_BLOCK__SOURCE_FILTER_STUB"),value:""}}function l(e){if(n.Type.isArray(e)){return e.reduce((function(e,t){if(n.Type.isPlainObject(t)&&n.Type.isString(t.name)&&n.Type.isString(t.value)){var r=n.Runtime.clone(t);if(!n.Type.isArray(r.filter)||r.filter.length<=0){r.filter=[n.Runtime.clone(a())]}if(!n.Type.isPlainObject(r.sort)||!n.Type.isArray(r.sort.items)){r.sort={items:[]}}return[].concat(babelHelpers.toConsumableArray(e),[r])}return e}),[])}return[]}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){babelHelpers.defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function u(e,t){return e.reduce((function(e,r){if(n.Type.isPlainObject(r)){return[].concat(babelHelpers.toConsumableArray(e),[s(s({},r),{},{url:t.url})])}return e}),[])}function c(e,t){var r=babelHelpers.slicedToArray(t,1),i=r[0];if(!n.Type.isPlainObject(e)){return{source:i.value,filter:u(babelHelpers.toConsumableArray(i.filter),i),sort:{by:i.sort.items[0].key,order:"DESC"}}}var a=t.find((function(t){return t.value===e.source}));if(!n.Type.isArray(e.filter)||e.filter.length<=0){if(a){e.filter=babelHelpers.toConsumableArray(a.filter)}}e.filter=u(e.filter,a);if(!n.Type.isPlainObject(e.sort)){e.sort={}}if(!n.Type.isString(e.sort.by)){if(a){e.sort.by=a.sort.items[0].value}}if(!n.Type.isString(e.sort.order)){e.sort.order="DESC"}return e}var d,p,f,g,h;function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){babelHelpers.defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var m=function(e){babelHelpers.inherits(r,e);function r(e){var t;babelHelpers.classCallCheck(this,r);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(r).call(this,e));n.Dom.addClass(t.layout,"landing-ui-field-source");t.items=l(e.items);t.value=c(e.value,t.items);t.cache=new n.Cache.MemoryCache;t.onButtonClick=t.onButtonClick.bind(babelHelpers.assertThisInitialized(t));t.onMenuItemClick=t.onMenuItemClick.bind(babelHelpers.assertThisInitialized(t));t.onSliderMessage=t.onSliderMessage.bind(babelHelpers.assertThisInitialized(t));t.onPlaceholderRemoveClick=t.onPlaceholderRemoveClick.bind(babelHelpers.assertThisInitialized(t));t.onPlaceholderClick=t.onPlaceholderClick.bind(babelHelpers.assertThisInitialized(t));n.Dom.append(t.getGrid(),t.layout);n.Dom.append(t.getSortByField().layout,t.layout);n.Dom.append(t.getSortOrderField().layout,t.layout);n.Dom.append(t.getValueLayoutWrapper(),t.header);t.setValue(t.value);window.top.BX.addCustomEvent("SidePanel.Slider:onMessage",t.onSliderMessage);return t}babelHelpers.createClass(r,[{key:"getItem",value:function e(t){return this.items.find((function(e){return e.value===t}))}},{key:"getButtonField",value:function e(){var t=this;return this.cache.remember("buttonField",(function(){return new BX.Landing.UI.Button.BaseButton("dropdown_button",{text:i.Loc.getMessage("LINK_URL_SUGGESTS_SELECT"),className:"landing-ui-button-select-link",onClick:t.onButtonClick})}))}},{key:"getSortByField",value:function e(){var t=this;return this.cache.remember("sortByField",(function(){var e=t.getItem(t.value.source);return new BX.Landing.UI.Field.DropdownInline({title:i.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_SORT_TITLE").toLowerCase(),items:e.sort.items,content:t.value.sort.by})}))}},{key:"getSortOrderField",value:function e(){var t=this;return this.cache.remember("sortOrderField",(function(){return new BX.Landing.UI.Field.DropdownInline({title:", ",items:[{name:i.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_SORT_DESC"),value:"DESC"},{name:i.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_SORT_ASC"),value:"ASC"}],content:t.value.sort.order})}))}},{key:"getValueLayout",value:function e(){return this.cache.remember("valueLayout",(function(){return n.Tag.render(d||(d=babelHelpers.taggedTemplateLiteral(["<span></span>"])))}))}},{key:"getValueLayoutWrapper",value:function e(){var t=this;return this.cache.remember("valueLayoutWrapper",(function(){return n.Tag.render(p||(p=babelHelpers.taggedTemplateLiteral(["<span>&nbsp;(",")</span>"])),t.getValueLayout())}))}},{key:"getInput",value:function e(){return this.input}},{key:"getGrid",value:function e(){var t=this;return this.cache.remember("grid",(function(){return n.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-field-source-grid">\n\t\t\t\t\t<div class="landing-ui-field-source-grid-left">','</div>\n\t\t\t\t\t<div class="landing-ui-field-source-grid-right">',"</div>\n\t\t\t\t</div>\n\t\t\t"])),t.getInput(),t.getButtonField().layout)}))}},{key:"onButtonClick",value:function e(){this.getMenu().show()}},{key:"onMenuItemClick",value:function e(t){var r=c({source:t.value},this.items);this.setValue(r);this.getMenu().close();this.openSourceFilterSlider(t.url)}},{key:"onPlaceholderClick",value:function e(t,r){r.preventDefault();this.openSourceFilterSlider(t.url)}},{key:"onPlaceholderRemoveClick",value:function e(t,r){r.preventDefault();r.stopPropagation();var i=r.currentTarget;if(n.Type.isDomNode(i)){var a=i.closest(".landing-ui-field-source-placeholder");if(a){n.Dom.remove(a)}if(this.getPlaceholders().length<=0){var l=c({source:this.getValue().source},this.items);this.value=l;this.setFilter(l.filter)}this.value.filter=this.getPlaceholders().map((function(e){return n.Dom.attr(e,"data-item")}))}}},{key:"onSliderMessage",value:function e(t){if(t.getEventId()==="save"){var r=b(b({},this.getValue()),{},{filter:t.getData().filter});var i=c(r,this.items);this.value=i;this.setFilter(i.filter)}}},{key:"openSourceFilterSlider",value:function e(r){if(n.Type.isString(r)){var i=t.Env.getInstance().getOptions().site_id;BX.SidePanel.Instance.open(r,{cacheable:false,requestMethod:"post",requestParams:{filter:this.getValue().filter,landingParams:{siteId:i}}})}}},{key:"getMenuItems",value:function e(){var t=this;return this.cache.remember("menuItems",(function(){return t.items.map((function(e){return{id:e.value,text:n.Text.encode(e.name),onclick:function r(){return t.onMenuItemClick(e)}}}))}))}},{key:"getMenu",value:function e(){var t=this;return this.cache.remember("menu",(function(){var e=t.input.closest(".landing-ui-field-source");var r=new BX.PopupMenuWindow({id:"".concat(t.selector,"_").concat(n.Text.getRandom()),bindElement:t.getButtonField().layout,autoHide:true,items:t.getMenuItems(),className:"landing-ui-field-source-popup",events:{onPopupShow:function i(){var a=n.Dom.getRelativePosition(t.getButtonField().layout,e);var l=0;var o=a.bottom;requestAnimationFrame((function(){n.Dom.style(r.popupWindow.popupContainer,{top:"".concat(o,"px"),left:"auto",right:"".concat(l,"px")})}))}}});n.Dom.append(r.popupWindow.popupContainer,e);return r}))}},{key:"addPlaceholder",value:function e(t){var r=n.Tag.render(g||(g=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<div class="landing-ui-field-source-placeholder">\n\t\t\t\t<span class="landing-ui-field-source-placeholder-text">',"</span>\n\t\t\t</div>\n\t\t"])),n.Text.encode(t.name));n.Dom.attr(r,{"data-item":t,title:t.name});if(!t.url){n.Dom.addClass(r.firstElementChild,"landing-ui-field-source-placeholder-text-plain")}if(t.url){var i=n.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span class="landing-ui-field-source-placeholder-remove"></span>\n\t\t\t'])));n.Dom.append(i,r);n.Event.bind(r,"click",this.onPlaceholderClick.bind(this,t));n.Event.bind(i,"click",this.onPlaceholderRemoveClick.bind(this,t))}n.Dom.append(r,this.input)}},{key:"getPlaceholders",value:function e(){return babelHelpers.toConsumableArray(this.input.querySelectorAll(".landing-ui-field-source-placeholder"))}},{key:"setFilter",value:function e(t){var r=this;n.Dom.clean(this.getInput());t.forEach((function(e){r.addPlaceholder(e)}))}},{key:"setSource",value:function e(t){var r=t.value,i=t.name;var a=this.getValueLayout();n.Dom.attr(a,"data-value",r);a.innerText=i}},{key:"setSortByItems",value:function e(t){if(n.Type.isArray(t)){this.getSortByField().setItems(t)}}},{key:"setValue",value:function e(t,r){var i=c(t,this.items);var a=this.getItem(t.source);if(n.Type.isPlainObject(a)){if(i.source!==this.value.source||this.getPlaceholders().length<=0){this.value=n.Runtime.clone(i);this.setFilter(i.filter);this.setSource(a);var l=this.getSortByField();l.setItems(a.sort.items);l.setValue(i.sort.by);var o=this.getSortOrderField();o.setValue(i.sort.order);if(!r){this.onValueChangeHandler(this)}}}}},{key:"getValue",value:function e(){var t=n.Runtime.clone(this.value);t.filter=t.filter.filter((function(e){return e.key!==a().key})).map((function(e){Reflect.deleteProperty(e,"url");return e}));t.sort.by=this.getSortByField().getValue();t.sort.order=this.getSortOrderField().getValue();return t}},{key:"getCurrentSource",value:function e(){var t=this.getValue();return this.getItem(t.source)}},{key:"isDetailPageAllowed",value:function e(){var t=this.getCurrentSource();return!n.Type.isPlainObject(t)||!n.Type.isPlainObject(t.settings)||t.settings.detailPage!==false}}]);return r}(r.BaseField);e.SourceField=m})(this.BX.Landing.UI.Field=this.BX.Landing.UI.Field||{},BX.Landing,BX.Landing.UI.Field,BX.Landing,BX);
//# sourceMappingURL=sourcefield.bundle.map.js